<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of mysql
 *
 * @author Christian Simon
 */
class MySql {

    private static $host = "localhost";
    private static $user = "vdl";
    private static $password = "25chris11";
    private static $database = "vdl_roleplay";

    public static function connect($host, $user, $password) {
        mysql_connect($host, $user, $password) or die("Eine Verbindung zum Server konnte nicht aufgebaut werden!");
    }

    public static function select_db($database) {
        mysql_select_db($database) or die("Eine Verbindung zur Datenbank konnte nicht aufgebaut werden!");
    }

    public static function query($string) {
        mysql_connect(self::$host, self::$user, self::$password) or die("Keine Verbindung moeglich");
        mysql_select_db(self::$database) or die("Die Datenbank existiert nicht.");
        $query = mysql_query($string);
        return $query;
    }

    public static function insert($string) {
        mysql_connect(self::$host, self::$user, self::$password) or die("Keine Verbindung moeglich");
        mysql_select_db(self::$database) or die("Die Datenbank existiert nicht.");
        $query = mysql_query($string);
        return mysql_affected_rows();
    }

    public static function getEnums($table, $column) {
        $sql = "SHOW COLUMNS FROM `" . $table . "` LIKE '" . $column . "'"; //SHOW COLUMNS FROM tbl_name LIKE 'feld1'
        $result = MySql::query($sql);
        $row = mysql_fetch_row($result);
        $enums = explode("','", preg_replace("/(enum|set)\('(.+?)'\)/", "\\2", $row[1]));
        return $enums;
    }

    public static function removeNull($obj) {
        foreach ($obj as $key => $val) {
            if ($val == "NULL" || $val == "null" || $val == null) {
                $obj->$key = "NULL";
                if($key == "description" || $key == "status" || $key == "shortdescription")
                    $obj->$key = "";
            }
        }
        return $obj;
    }

}

?>
